package com.skateboard.reelviewtest.loopviewpager

import android.content.Context
import android.graphics.Color
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.viewpager.widget.PagerAdapter

/**
 * @作者： xuze
 * @时间： 2021/3/4 10:57 AM
 * @描述：
 */
class MyPagerAdapter (context: Context?): PagerAdapter() {
    var context: Context? = null
    var dataProvider : DataProvider2? = null
    init {
        this.context=context
        dataProvider = DataProvider2()
    }


    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view === `object`
    }

    override fun getCount(): Int {
        return Int.MAX_VALUE
    }


    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        //super.destroyItem(container, position, `object`)
        var tv=container.findViewById<TextView>(position)
        if(tv!=null){
            container.removeView(tv)
        }
        Log.e("ssss","=====destroyItem=========:${tv==null}")

    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {

        var text : String? = ""
        text = dataProvider?.getData(position)
        Log.e("ssss","instantiateItem:position$position==============text:$text")
        var tv = TextView(context)
        tv.setTextColor(Color.BLACK)
        tv.textSize = 24f
       // tv.text = "AdapterPosition is :$position \n Content value:$text"
        tv.id=position
        container.addView(tv)
        return tv
    }
}